package com.bright.hxj.qchz.service.impl;

import com.bright.hxj.qchz.service.LockManager;
import org.springframework.stereotype.Component;

import java.util.concurrent.ConcurrentHashMap; /**
 * @Author hxj
 * @Date 2025/1/20 11:40
 * @Description
 */

@Component
public class LockManagerImpl implements LockManager {

    private static final ConcurrentHashMap<String, Object> concurrentMap = new ConcurrentHashMap<>();

    @Override
    public Object getLock(String lockName) {
        if (!concurrentMap.containsKey(lockName)) {
            concurrentMap.putIfAbsent(lockName, new Object());
        }
        return concurrentMap.get(lockName);
        // TODO 该map中的内容会越来越多直到撑爆内存 设计定时清理内容机制 比如1小时过期
    }


}
